package com.youyi.yychosesdk.ui.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lkx.liandianqinew.R;
import com.youyi.yychosesdk.constant.Type;
import com.youyi.yychosesdk.result.Result;
import com.youyi.yychosesdk.setting.Setting;
import com.youyi.yychosesdk.ui.widget.PressedImageView;
import com.youyi.yychosesdk.utils.media.DurationUtils;

public class PreviewPhotosFragmentAdapter extends RecyclerView.Adapter<PreviewPhotosFragmentAdapter.PreviewPhotoVH> {
    private int checkedPosition = -1;
    private LayoutInflater inflater;
    private OnClickListener listener;

    public interface OnClickListener {
        void onPhotoClick(int i);
    }

    public PreviewPhotosFragmentAdapter(Context context, OnClickListener onClickListener) {
        this.inflater = LayoutInflater.from(context);
        this.listener = onClickListener;
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public PreviewPhotoVH onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new PreviewPhotoVH(this.inflater.inflate(R.layout.item_preview_selected_photos_easy_photos, viewGroup, false));
    }

    public void onBindViewHolder(PreviewPhotoVH previewPhotoVH, final int i) {
        String photoPath = Result.getPhotoPath(i);
        String photoType = Result.getPhotoType(i);
        Uri photoUri = Result.getPhotoUri(i);
        long photoDuration = Result.getPhotoDuration(i);
        boolean z = photoPath.endsWith(Type.GIF) || photoType.endsWith(Type.GIF);
        if (Setting.showGif && z) {
            Setting.imageEngine.loadGifAsBitmap(previewPhotoVH.ivPhoto.getContext(), photoUri, previewPhotoVH.ivPhoto);
            previewPhotoVH.tvType.setText(R.string.gif_easy_photos);
            previewPhotoVH.tvType.setVisibility(View.VISIBLE);
        } else if (!Setting.showVideo || !photoType.contains(Type.VIDEO)) {
            Setting.imageEngine.loadPhoto(previewPhotoVH.ivPhoto.getContext(), photoUri, previewPhotoVH.ivPhoto);
            previewPhotoVH.tvType.setVisibility(View.GONE);
        } else {
            Setting.imageEngine.loadPhoto(previewPhotoVH.ivPhoto.getContext(), photoUri, previewPhotoVH.ivPhoto);
            previewPhotoVH.tvType.setText(DurationUtils.format(photoDuration));
            previewPhotoVH.tvType.setVisibility(View.VISIBLE);
        }
        if (this.checkedPosition == i) {
            previewPhotoVH.frame.setVisibility(View.VISIBLE);
        } else {
            previewPhotoVH.frame.setVisibility(View.GONE);
        }
        previewPhotoVH.ivPhoto.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yychosesdk.ui.adapter.PreviewPhotosFragmentAdapter.AnonymousClass1 */

            public void onClick(View view) {
                PreviewPhotosFragmentAdapter.this.listener.onPhotoClick(i);
            }
        });
    }

    @Override // android.support.v7.widget.RecyclerView.Adapter
    public int getItemCount() {
        return Result.count();
    }

    public void setChecked(int i) {
        if (this.checkedPosition != i) {
            this.checkedPosition = i;
            notifyDataSetChanged();
        }
    }

    /* access modifiers changed from: package-private */
    public class PreviewPhotoVH extends RecyclerView.ViewHolder {
        View frame;
        PressedImageView ivPhoto;
        TextView tvType;

        public PreviewPhotoVH(View view) {
            super(view);
            this.ivPhoto = (PressedImageView) view.findViewById(R.id.iv_photo);
            this.frame = view.findViewById(R.id.v_selector);
            this.tvType = (TextView) view.findViewById(R.id.tv_type);
        }
    }
}
